//
//  BigImageScrollView.m
//  Product_NEWS
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 FCH. All rights reserved.
//

#import "BigImageScrollView.h"
#import "UIImageView+WebCache.h"
@interface BigImageScrollView ()<UIScrollViewDelegate>
@property (nonatomic, retain) UIImageView *bigImageView;
@end

@implementation BigImageScrollView

-(instancetype)initWithFrame:(CGRect)frame
                PictureModel:(PictureModel *)model{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView:model];
    }
    return self;
    
}

//http://thenewself.blog.163.com/blog/static/198501330201221862929331/  图片居中

-(void)createSubView:(PictureModel *)model
{
    
    self.bigImageView = [[UIImageView alloc]init];
    
    
   
    
    
    //图片调整
    CGFloat picWidth = self.frame.size.width;
    CGFloat scale = picWidth / model.width; //缩放比例
    CGFloat picHeight = (CGFloat)model.height  * scale;
 
    self.bigImageView.frame = CGRectMake(0, 0, self.frame.size.width , picHeight);
  
    //图片居中
    if (picHeight < self.frame.size.height) {
        self.bigImageView.center = self.center;
    }
    [self.bigImageView sd_setImageWithURL:[NSURL URLWithString:model.image1] placeholderImage:[UIImage imageNamed:@"background"]];
    self.maximumZoomScale = 3.0;
    self.delegate = self;
    [self addSubview:self.bigImageView];
    [_bigImageView release];
    
}





-(void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    
    if (self.bigImageView.frame.size.height > self.frame.size.height) {
        [self.bigImageView setCenter:CGPointMake(scrollView.contentSize.width / 2, scrollView.contentSize.height / 2)];
    }else {
        [self.bigImageView setCenter:CGPointMake(scrollView.contentSize.width / 2, scrollView.frame.size.height / 2)];
    }

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    // 缩放
    return self.bigImageView;
}

@end
